#include <iostream>
#include <stdlib.h>

#define totalSize 40
#define maxSize 30
typedef struct{
    char data;
    int weight;
    int lchild,rchild;
}HFNode;

typedef struct{
    HFTree elem[totalSize];
    int num;
    int root;
}HFTree;





void create(HFTree &Tree,HFTree &Finished){
    
    int l=0,r=1;
    if (Tree.elem[r].weight<Tree.elem[l].weight){r=0;l=1;}
    for (int i=0;i<Tree.num;i++){
        if (Tree.elem[i].weight<Tree.elem[r].weight){r=i;}
        if (Tree.elem[r].weight<Tree.elem[l].weight){r=l;l=i;}
    }//获得最小的两个编号
    HFNode NewNode;
    NewNode.weight=Tree.elem[l].weight+Tree.elem[l].weight;
    NewNode.lchild=l;
    NewNode.rchild=r;
    Finished.elem[Finished.num]=NewNode;
    Tree.num--;
    Finished.num++;

    if (Tree.num==1) insert;
}

void insert(HFNode NewNode,HFTree &Finished){
    
    Finished.num++;
    int i=Finished.num-1;
    while(i!=0 && NewNode.weight>Finished.elem[i/2].weight){
		Finished.elem[i] =Finished.elem[i/2];
		i = i/2;
	}
    Finished.elem[i] = NewNode;
    Finished.elem[Finished.num]=Finished.elem[2*i+1];
    Finished.elem[2*i+1];
}

int n;
int *a;
int main(){
    a=(int *) malloc(n*sizeof(int));
    HFTree Tree;
    for (int i=0;i<n;i++){
        HFNode newnode;
        newnode.weight=a[i];
        Tree.root+=a[i];
        newnode.lchild=-1;
        newnode.rchild=-1;
    }
    HFTree Finished;
    Finished.num=0;
    Finished.root=0;
    create(Tree,Finished);

}